package cn.iocoder.yudao.module.wrdk.controller.admin.licence;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wrdk.controller.admin.licence.vo.*;
import cn.iocoder.yudao.module.wrdk.dal.dataobject.licence.wrdklicenceDO;
import cn.iocoder.yudao.module.wrdk.convert.licence.wrdklicenceConvert;
import cn.iocoder.yudao.module.wrdk.service.licence.wrdklicenceService;

@Api(tags = "Crazy!!!!!管理后台 - 地块许可证")
@RestController
@RequestMapping("/wrdk/wrdklicence")
@Validated
public class wrdklicenceController {

    @Resource
    private wrdklicenceService wrdklicenceService;

    @PostMapping("/create")
    @ApiOperation("创建地块许可证")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicence:create')")
    public CommonResult<Long> createwrdklicence(@Valid @RequestBody wrdklicenceCreateReqVO createReqVO) {
        return success(wrdklicenceService.createwrdklicence(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新地块许可证")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicence:update')")
    public CommonResult<Boolean> updatewrdklicence(@Valid @RequestBody wrdklicenceUpdateReqVO updateReqVO) {
        wrdklicenceService.updatewrdklicence(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除地块许可证")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicence:delete')")
    public CommonResult<Boolean> deletewrdklicence(@RequestParam("id") Long id) {
        wrdklicenceService.deletewrdklicence(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得地块许可证")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicence:query')")
    public CommonResult<wrdklicenceRespVO> getwrdklicence(@RequestParam("id") Long id) {
        wrdklicenceDO wrdklicence = wrdklicenceService.getwrdklicence(id);
        return success(wrdklicenceConvert.INSTANCE.convert(wrdklicence));
    }

    @GetMapping("/list")
    @ApiOperation("获得地块许可证列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicence:query')")
    public CommonResult<List<wrdklicenceRespVO>> getwrdklicenceList(@RequestParam("ids") Collection<Long> ids) {
        List<wrdklicenceDO> list = wrdklicenceService.getwrdklicenceList(ids);
        return success(wrdklicenceConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得地块许可证分页")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicence:query')")
    public CommonResult<PageResult<wrdklicenceRespVO>> getwrdklicencePage(@Valid wrdklicencePageReqVO pageVO) {
        PageResult<wrdklicenceDO> pageResult = wrdklicenceService.getwrdklicencePage(pageVO);
        return success(wrdklicenceConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出地块许可证 Excel")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicence:export')")
    @OperateLog(type = EXPORT)
    public void exportwrdklicenceExcel(@Valid wrdklicenceExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<wrdklicenceDO> list = wrdklicenceService.getwrdklicenceList(exportReqVO);
        // 导出 Excel
        List<wrdklicenceExcelVO> datas = wrdklicenceConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "地块许可证.xls", "数据", wrdklicenceExcelVO.class, datas);
    }

}
